#include <stdio.h>

int searchInsert(int *nums, int numSize, int target)
{
    int left = 0;
    int right = numSize - 1;
    while (left <= right)
    {
        int mid = left + (right - left) / 2;

        if (nums[mid] == target)
        {
            return mid;
        }
        else if (nums[mid] < target)
        {
            left = mid + 1;
        }
        else
        {
            right = mid - 1;
        }
    }

    return left;
}

int main(int argc, char const *argv[])
{
    int nums[10] = {1,3,6,7,9};
    int length = sizeof(nums) / sizeof(nums[0]);
    int target = 8;
    int s = searchInsert(nums,length,target);
    printf("s = %d\n",s);
    return 0;
}
